package com.opencv.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.opencv.formatter.DateFormatterLongAnnotationIntrospector;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

import java.nio.charset.StandardCharsets;
import java.util.TimeZone;

/**
 * @author qz.wu
 * @date 2021/11/24 9:04
 * @descriptions 配置Date类型转Long时间戳格式
 */
@Configuration
public class WebServerConfig {

    @Bean
    public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();

        // 不设置Utf-8格式,可能会导致Mock测试输出信息乱码
        converter.setDefaultCharset(StandardCharsets.UTF_8);

        ObjectMapper objectMapper = converter.getObjectMapper();
        objectMapper.setTimeZone(TimeZone.getDefault());
        objectMapper.setAnnotationIntrospector(new DateFormatterLongAnnotationIntrospector());
        return converter;
    }
}
